#include <sourcemod>
#include <sdktools>
#include <colors>
#include "l4d2_InfectedSpawnApi.inc"

#define PLUGIN_VERSION "2.x"
#define DEBUG 0
#define CVAR_FLAGS FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_NOTIFY


//自定义
#define TANKRY        1 //熔岩坦克
#define TANKZL        2 //重力坦克
#define TANKKJ        3 //恐惧坦克
#define TANKYL        4 //幽灵坦克
#define TANKDZ        5 //地震坦克
#define TANKYJ        6 //游击坦克

#define SURVIVOR    2
#define CLASS_TANK    8
#define MOLOTOV     0
#define EXPLODE     1
#define ENTITY_GASCAN    "models/props_junk/gascan001a.mdl"
#define ENTITY_PROPANE    "models/props_junk/propanecanister001a.mdl"

/* Sound */
#define SOUND_EXPLODE    "animation/bombing_run_01.wav"
#define SOUND_SPAWN        "music/pzattack/contusion.wav"
#define SOUND_BCLAW        "weapons/grenade_launcher/grenadefire/grenade_launcher_explode_1.wav"
#define SOUND_GCLAW        "plats/churchbell_end.wav"
#define SOUND_DCLAW        "ambient/random_amb_sounds/randbridgegroan_03.wav"
#define SOUND_QUAKE        "player/charger/hit/charger_smash_02.wav"
#define SOUND_STEEL        "physics/metal/metal_solid_impact_hard5.wav"
#define SOUND_CHANGE    "items/suitchargeok1.wav"
#define SOUND_HOWL        "player/tank/voice/pain/tank_fire_08.wav"
#define SOUND_WARP        "ambient/energy/zap9.wav"

/* Particle */
#define PARTICLE_SPAWN    "electrical_arc_01_system"
#define PARTICLE_DEATH    "gas_explosion_main"
#define PARTICLE_THIRD    "apc_wheel_smoke1"
#define PARTICLE_FORTH    "aircraft_destroy_fastFireTrail"
#define PARTICLE_WARP    "water_splash"


/* Parameter */
new Handle:sm_lastboss_enable                = INVALID_HANDLE;
new Handle:sm_lastboss_stealth_third         = INVALID_HANDLE;
new Handle:sm_lastboss_gravityinterval         = INVALID_HANDLE;
new Handle:sm_lastboss_quake_radius         = INVALID_HANDLE;
new Handle:sm_lastboss_quake_force             = INVALID_HANDLE;
new Handle:sm_lastboss_dreadinterval         = INVALID_HANDLE;
new Handle:sm_lastboss_dreadrate             = INVALID_HANDLE;

/***** 自定义 ******/
new Handle:sm_lastboss_tankry_health        = INVALID_HANDLE;
new Handle:sm_lastboss_tankzl_health        = INVALID_HANDLE;
new Handle:sm_lastboss_tankkj_health        = INVALID_HANDLE;
new Handle:sm_lastboss_tankyl_health        = INVALID_HANDLE;
new Handle:sm_lastboss_tankdz_health        = INVALID_HANDLE;
new Handle:sm_lastboss_tankyj_health        = INVALID_HANDLE;

new Handle:sm_lastboss_tankry_speed        = INVALID_HANDLE;
new Handle:sm_lastboss_tankzl_speed        = INVALID_HANDLE;
new Handle:sm_lastboss_tankkj_speed        = INVALID_HANDLE;
new Handle:sm_lastboss_tankyl_speed        = INVALID_HANDLE;
new Handle:sm_lastboss_tankdz_speed        = INVALID_HANDLE;
new Handle:sm_lastboss_tankyj_speed        = INVALID_HANDLE;

new Handle:sm_lastboss_tankry_hxdmg        = INVALID_HANDLE;

new Handle:Msg_Timer                            = INVALID_HANDLE;
new tanktype[MAXPLAYERS+1];
new clientlosscount[MAXPLAYERS+1];  // 丢失tank次数
new changehealth = 0;


/* Grobal */
new alpharate;
new visibility;
new g_iVelocity    = -1;
new g_iLaggedMovementO    = -1;

public Plugin:myinfo =
{
    name = "[L4D2]变身坦克加强对抗版",
    author = "ztar & 鸭蛋加强",
    description = "Special Tank spawns during finale.",
    version = PLUGIN_VERSION,
    url = "http://ztar.blog7.fc2.com/"
}

/******************************************************
*    插件初始化
*******************************************************/
public OnPluginStart()
{
    decl String:game_name[64];
    GetGameFolderName(game_name, sizeof(game_name));
    if (!StrEqual(game_name, "left4dead", false) && !StrEqual(game_name, "left4dead2", false))
    {
        SetFailState("该插件只能用于l4d和l4d2.");
    }
    // 创建特感
    InitInfectedSpawnAPI();

    /* 启用/关闭 */
    sm_lastboss_enable            = CreateConVar("sm_lastboss_enable","1","启用变身坦克.(0:否 1:是)", CVAR_FLAGS);

    /* 技能 */
    sm_lastboss_stealth_third        = CreateConVar("sm_lastboss_stealth_third", "1.0", "隐形技能多少秒后完全隐形", CVAR_FLAGS);
    sm_lastboss_gravityinterval        = CreateConVar("sm_lastboss_gravityinterval", "5.0", "重力技能击中后重力持续的时间", CVAR_FLAGS);
    sm_lastboss_quake_radius            = CreateConVar("sm_lastboss_quake_radius", "800.0", "地震技能的半径", CVAR_FLAGS);
    sm_lastboss_quake_force            = CreateConVar("sm_lastboss_quake_force", "400.0", "地震技能的威力", CVAR_FLAGS);
    sm_lastboss_dreadinterval        = CreateConVar("sm_lastboss_dreadinterval", "9.0", "致盲技能的持续时间", CVAR_FLAGS);
    sm_lastboss_dreadrate            = CreateConVar("sm_lastboss_dreadrate", "252", "致盲技能致盲程度", CVAR_FLAGS);

    /**************************** 自定义 *******************************/
    /* 技能 */
    sm_lastboss_tankry_hxdmg            = CreateConVar("sm_lastboss_tankry_hxdmg", "10", "红血攻击造成的附加伤害", CVAR_FLAGS);

    /* 生命值 */
    sm_lastboss_tankry_health = CreateConVar("sm_lastboss_tankry_health", "50000", "熔岩坦克的生命值", CVAR_FLAGS);
    sm_lastboss_tankzl_health = CreateConVar("sm_lastboss_tankzl_health", "50000", "重力坦克的生命值", CVAR_FLAGS);
    sm_lastboss_tankkj_health = CreateConVar("sm_lastboss_tankkj_health", "65000", "恐惧坦克的生命值", CVAR_FLAGS);
    sm_lastboss_tankyl_health = CreateConVar("sm_lastboss_tankyl_health", "65000", "幽灵坦克的生命值", CVAR_FLAGS);
    sm_lastboss_tankdz_health = CreateConVar("sm_lastboss_tankdz_health", "65000", "地震坦克的生命值", CVAR_FLAGS);
    sm_lastboss_tankyj_health = CreateConVar("sm_lastboss_tankyj_health", "60000", "游击坦克的生命值", CVAR_FLAGS);

    /* 速度 */

    sm_lastboss_tankry_speed = CreateConVar("sm_lastboss_tankry_speed", "1.30", "熔岩坦克的移动倍数", CVAR_FLAGS);
    sm_lastboss_tankzl_speed = CreateConVar("sm_lastboss_tankzl_speed", "1.25", "重力坦克的移动倍数", CVAR_FLAGS);
    sm_lastboss_tankkj_speed = CreateConVar("sm_lastboss_tankkj_speed", "1.25", "恐惧坦克的移动倍数", CVAR_FLAGS);
    sm_lastboss_tankyl_speed = CreateConVar("sm_lastboss_tankyl_speed", "1.50", "幽灵坦克的移动倍数", CVAR_FLAGS);
    sm_lastboss_tankdz_speed = CreateConVar("sm_lastboss_tankdz_speed", "1.30", "地震坦克的移动倍数", CVAR_FLAGS);
    sm_lastboss_tankyj_speed = CreateConVar("sm_lastboss_tankyj_speed", "2.90", "游击坦克的移动倍数", CVAR_FLAGS);

    /* Event hook */
    HookEvent("round_start", Event_Round_Start);
    HookEvent("tank_spawn", Event_Tank_Spawn);
    HookEvent("tank_frustrated", Event_Tank_Frustrated);
    HookEvent("player_death", Event_Player_Death);
    HookEvent("player_hurt", Event_Player_Hurt);
    HookEvent("player_incapacitated", Event_Player_Hurt);
    HookEvent("player_team", Event_Player_Team);
    
    RegConsoleCmd("sm_tank", SmSetTank);

    //AutoExecConfig(true, "l4d2_lastboss_yd");

    g_iVelocity             =     FindSendPropOffs("CBasePlayer", "m_vecVelocity[0]");
    g_iLaggedMovementO    =    FindSendPropInfo("CTerrorPlayer","m_flLaggedMovementValue");
    if(g_iVelocity == -1)
        LogError("Could not find offset for CBasePlayer::m_vecVelocity[0]");
}

/******************************************************
*    Initial functions
*******************************************************/
InitPrecache()
{
    /* Precache models */
    PrecacheModel(ENTITY_PROPANE, true);
    PrecacheModel(ENTITY_GASCAN, true);

    /* Precache sounds */
    PrecacheSound(SOUND_EXPLODE, true);
    PrecacheSound(SOUND_SPAWN, true);
    PrecacheSound(SOUND_BCLAW, true);
    PrecacheSound(SOUND_GCLAW, true);
    PrecacheSound(SOUND_DCLAW, true);
    PrecacheSound(SOUND_QUAKE, true);
    PrecacheSound(SOUND_STEEL, true);
    PrecacheSound(SOUND_CHANGE, true);
    PrecacheSound(SOUND_HOWL, true);
    PrecacheSound(SOUND_WARP, true);

    /* Precache particles */
    PrecacheParticle(PARTICLE_SPAWN);
    PrecacheParticle(PARTICLE_DEATH);
    PrecacheParticle(PARTICLE_THIRD);
    PrecacheParticle(PARTICLE_FORTH);
    PrecacheParticle(PARTICLE_WARP);
}

InitData()
{
    /* Reset flags */
    for (new i = 1; i <= MaxClients; i++)
    {
        if (i > 32) { return; }
        tanktype[i] = 0;
        clientlosscount[i] = 0;
    }
    changehealth = 0;
}

public OnMapStart()
{
    InitPrecache();
    InitData();
    CreateTimer(2.0, Timer_Tank_Select_Msg, 0, TIMER_REPEAT);
}

public OnMapEnd()
{
    InitData();
    if (Msg_Timer != INVALID_HANDLE)
    {
        KillTimer(Msg_Timer);
    }
}

public Action:Event_Round_Start(Handle:event, const String:name[], bool:dontBroadcast)
{
    InitData();
}

/******************************************************
*    坦克产生事件
*******************************************************/
public Action:Event_Tank_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(!GetConVarInt(sm_lastboss_enable)) { return; }
    new client = GetClientOfUserId(GetEventInt(event, "userid"));
    /* Reset flags */
    clientlosscount[client] = 0;

    if(IsValidPlayer(client) && IsValidEntity(client))
    {
        if (tanktype[client] >= 1)    // 玩家选择tank技能
        {
            SetTankType(client, tanktype[client]);
        }
        else
        {
            new randomtank = GetRandomInt(1, 6); // 给予随机技能
            SetTankType(client, randomtank);
        }

        for(new j = 1; j <= MaxClients; j++)
        {
            if(IsClientInGame(j) && !IsFakeClient(j))
            {
                EmitSoundToClient(j, SOUND_SPAWN);  // 声音效果
            }
        }
        // 检测tank丢控制事件，创建后10秒运行执行
        if (IsValidPlayer(client) && IsValidEntity(client))
        {
            CreateTimer(10.0, CheckFrustration, client);
        }
    }
}
/******************************************************
*    AI坦克
*******************************************************/
public Action:L4D_OnSpawnTank(const Float:vector[3], const Float:qangle[3])
{
    // 直接产生
    new random_client = GetRandomPlayer(3);
    if(IsValidPlayer(random_client, false,true))
    {
        TankSpawner(random_client);    // 指定为某个玩家
    }
    return Plugin_Continue;
}


/******************************************************
*    坦克更换控制者
*******************************************************/
public Action:Event_Tank_Frustrated(Handle:event, const String:name[], bool:dontBroadcast)
{
    new userid = GetClientOfUserId(GetEventInt(event, "userid"));
    PrintToChatAll("插件运行出错，请截图给Yd技术一夜男或曼陀罗");
    PrintToChatAll("插件运行出错，请截图给Yd技术一夜男或曼陀罗");
    PrintToChatAll("插件运行出错，请截图给Yd技术一夜男或曼陀罗");
    TankChange(userid);
}

/******************************************************
*    玩家/坦克死亡事件
*******************************************************/
public Action:Event_Player_Death(Handle:event, const String:name[], bool:dontBroadcast)
{
    new client = GetClientOfUserId(GetEventInt(event, "userid"));

    if(client <= 0 || client > MaxClients)
        return;
    if(!IsClientInGame(client) || !IsValidEntity(client))
        return;
    if(GetClientTeam(client) != 3 || GetEntProp(client, Prop_Send, "m_zombieClass") != CLASS_TANK)
        return;

    if(GetConVarInt(sm_lastboss_enable))
    {
        /* 死亡时产生爆炸和火焰 */
        if(IsPlayerTank(client))
        {
            decl Float:Pos[3];
            GetClientAbsOrigin(client, Pos);
            EmitSoundToAll(SOUND_EXPLODE, client);
            ShowParticle(Pos, PARTICLE_DEATH, 5.0);
            LittleFlower(Pos, EXPLODE);
            CPrintToChatAll("{olive}%N {lightgreen}坦克已经死亡!", client);            
        }
		//重力恢复
        SetEntityGravity(client, 1.0);
	}
}

/******************************************************
*    tank循环检测控制权事件
*******************************************************/
public Action:CheckFrustration(Handle:timer, any:client)
{
    if (!IsClientConnected(client) || !IsClientInGame(client) || IsFakeClient(client) || (GetClientTeam(client)!=3) || !IsPlayerTank(client) || !IsPlayerAlive(client)) return;
    new frustration = GetEntProp(client, Prop_Send, "m_frustration");
    if (frustration >= 95)
    {
        // 杀死，2次CD
        clientlosscount[client]++;
        if (clientlosscount[client] >= 2)
        {// 处死
            clientlosscount[client] = 0;
            SetEntProp(client, Prop_Send, "m_frustration", 0);// 重置CD时间
            ForcePlayerSuicide(client);// 处死
            PrintHintTextToAll("因丢失2次Tank控制权，玩家【 %N 】已被处死", client);
            //ChangeClientTeam(client, 1); // 旁观/
            ///FakeClientCommand(client, "jointeam 3");
            //CreateTimer(0.1, RestoreInfectedTeam, client);  // 再次进入感染者
        }
        else
        {
            PrintHintTextToAll("玩家【 %N 】丢失Tank控制一次，下次丢失将被直接处死", client);
            SetEntProp(client, Prop_Send, "m_frustration", 0);   // 第二次控制CD重置
            CreateTimer(0.1, CheckFrustration, client);
        }
    }
    else
    {// 循环执行此事件
        CreateTimer(0.1+(95-frustration)*0.1, CheckFrustration, client);
    }
}
// 为系统AItank指定随机接受者并设置属性与控制CD等
public Action:SpawnAITank(Handle:timer)
{
    new client = GetRandomPlayer(3);
    if(IsValidPlayer(client, false,true))
    {
        TankSpawner(client);    // 指定为某个玩家
    }
    else
    {
        PrintToChatAll("[丫蛋]没有发现合适的玩家成为坦克,请稍后再试!");
        return;
    }
    
    if(IsValidPlayer(client) && IsValidEntity(client))
    {
        {
            if (tanktype[client] >= 1)    // 玩家选择tank技能
            {
                SetTankType(client, tanktype[client]);
            }
            else
            {
                new randomtank = GetRandomInt(1, 6); // 给予随机技能
                SetTankType(client, randomtank);
            }
        }

        for(new j = 1; j <= MaxClients; j++)
        {
            if(IsClientInGame(j) && !IsFakeClient(j))
            {
                EmitSoundToClient(j, SOUND_SPAWN);  // 声音效果
            }
        }
        // 检测tank丢控制事件，创建后10秒运行执行
        if (IsValidPlayer(client) && IsValidEntity(client))
        {
            CreateTimer(10.0, CheckFrustration, client);
        }
    }
}
public Action:RestoreInfectedTeam(Handle:timer, any:client)
{
    if (!IsClientConnected(client) || !IsClientInGame(client) || IsFakeClient(client) || (GetClientTeam(client)==3)) return;
    FakeClientCommand(client, "jointeam 3");
}

static bool:reswapInfected[MAXPLAYERS+1];
static bool:reghostInfected[MAXPLAYERS+1];
static bool:respawnInfected[MAXPLAYERS+1];
static infectedClass[MAXPLAYERS+1];
static infectedHealth[MAXPLAYERS+1];
static Float:vectors[MAXPLAYERS+1][3];
static Float:infangles[MAXPLAYERS+1][3];
static Float:velocity[MAXPLAYERS+1][3];
static const Float:nullorigin[3];

// 指定某个玩家为tank接受者
static TankSpawner(client)
{    
    for (new i=1; i<=MaxClients; i++) //now to 'disable' all but the guy who is to be tank
    {
        if (i == client) continue; //dont disable the chosen one
        if (!IsClientInGame(i)) continue; //not ingame? skip
        if (GetClientTeam(i) != 3) continue; //not infected? skip
        if (IsFakeClient(i)) continue; //a bot? skip

        if (IsPlayerAlive(i))
        {
            respawnInfected[i] = true;
            if (IsPlayerGhost(i)) reghostInfected[i] = true;
            infectedClass[i] = GetEntProp(i, Prop_Send, "m_zombieClass");
            infectedHealth[i] = GetClientHealth(i);
            GetClientAbsOrigin(i, vectors[i]);
            GetClientEyeAngles(i, infangles[i]);
            GetEntPropVector(i, Prop_Data, "m_vecVelocity", velocity[i])
            
            //TeleportEntity(i, nullorigin, NULL_VECTOR, NULL_VECTOR);
            //ForcePlayerSuicide(i);
        }        
        //ChangeClientTeam(i, 1);
        reswapInfected[i] = true;
    }
    CreateTimer(0.1, RevertPlayerStatus);
}

public Action:RevertPlayerStatus(Handle:timer)
{
    // We restore the player's status
    for (new i=1; i<=MaxClients; i++)
    {
        if (reswapInfected[i])
        {
            //ChangeClientTeam(i, 3);
            reswapInfected[i] = false;
        }
        
        if (respawnInfected[i] && IsValidEntity(i))
        {
            //SpawnInfectedBoss(i, infectedClass[i], reghostInfected[i], false, ItsFinaleTime(), vectors[i], infangles[i], velocity[i]);
            SetEntityHealth(i, infectedHealth[i]);
            respawnInfected[i] = false;
        }
    }
}

stock bool:ItsFinaleTime()
{
    new ent = FindEntityByClassname(-1, "terror_player_manager");

    if (ent > -1)
    {
        new offset = FindSendPropInfo("CTerrorPlayerResource", "m_isFinale");
        if (offset > 0)
        {
            if (GetEntData(ent, offset))
            {
                if (GetEntData(ent, offset) == 1) return true;
            }
        }
    }
    return false;
}

/******************************************************
*    玩家队伍转换
*******************************************************/
public Action:Event_Player_Team(Handle:event, const String:name[], bool:dontBroadcast)
{
    new userid = GetClientOfUserId(GetEventInt(event,"userid"));
    if (userid <= 0 || userid > MaxClients || !IsClientInGame(userid)) { return; }
    new team = GetClientTeam(userid);
    if (IsPlayerTank(userid) && IsPlayerAlive(userid) && team == 3)
    {
        TankChange(userid);
    }
}

/******************************************************
*    被攻击时产生的技能
*******************************************************/
public Action:Event_Player_Hurt(Handle:event, const String:name[], bool:dontBroadcast)
{
    new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
    new target = GetClientOfUserId(GetEventInt(event, "userid"));


    decl String:weapon[64];
    GetEventString(event, "weapon", weapon, sizeof(weapon));

    if(attacker < 1 || attacker > MaxClients || target < 1 ||  target > MaxClients)
        return;

    if(!IsClientInGame(attacker) || !IsClientInGame(target))
        return;


    if(GetConVarInt(sm_lastboss_enable))
    {
        if(StrEqual(weapon, "tank_claw") && IsPlayerTank(attacker))
        {
            if (!IsValidEntity(attacker)) { return; }
            if (GetClientTeam(attacker) == GetClientTeam(target)) { return; }
            //PrintToChatAll("玩家: %N 普通攻击.", attacker);
            if(tanktype[attacker] == TANKDZ)
            {
                /* 地震技能(被攻击者已经倒地) */
                SkillEarthQuake(target, attacker);
                //PrintToChatAll("玩家: %N 触发地震技能.", attacker);
            }
            if(tanktype[attacker] == TANKZL)
            {
                /* 重力攻击 */
                SkillGravityClaw(target);
                //PrintToChatAll("玩家: %N 触发重力技能.", attacker);
            }
            if(tanktype[attacker] == TANKKJ)
            {
                /* 致盲攻击 */
                SkillDreadClaw(target);
                //PrintToChatAll("玩家: %N 触发致盲技能.", attacker);
            }
            if(tanktype[attacker] == TANKRY)
            {
                /* 红血攻击 */
                SkillBurnClaw(target, 1);
                //PrintToChatAll("玩家: %N 触发红血技能.", attacker);
            }

        }

        if(StrEqual(weapon, "tank_rock") && IsPlayerTank(attacker))
        {
            if (!IsValidEntity(attacker)) { return; }
            if (GetClientTeam(attacker) == GetClientTeam(target)) { return; }
            //PrintToChatAll("玩家: %N 丢石头攻击.", attacker);
            if(tanktype[attacker] == TANKRY)
            {
                /* 火焰石头 */
                SkillCometStrike(target, MOLOTOV);
                //PrintToChatAll("玩家: %N 触发火焰石头.", attacker);
            }
            else if (tanktype[attacker] == TANKDZ)
            {
                /* 爆炸石头 */
                SkillCometStrike(target, EXPLODE);
                //PrintToChatAll("玩家: %N 触发爆炸石头.", attacker);
            }
        }

        if(StrEqual(weapon, "melee") || StrEqual(weapon, "chainsaw"))
        {
            if (!IsPlayerTank(attacker)) { return; }
            if (!IsValidEntity(target)) { return; }
            //PrintToChatAll("玩家: %N 被近战攻击", target);
            if (GetClientTeam(attacker) == GetClientTeam(target)) { return; }
            if(tanktype[target] == TANKZL)
            {
                /* 钢铁皮肤 */
                EmitSoundToClient(attacker, SOUND_STEEL);
                SetEntityHealth(target, (GetEventInt(event,"dmg_health") + GetEventInt(event,"health")));
                //PrintToChatAll("玩家: %N 触发钢铁皮肤", target);
            }
            if(tanktype[target] == TANKRY)
            {
                /* 火焰喷发 */
                SkillFlameGush(attacker, target);
                //PrintToChatAll("玩家: %N 触发火焰喷发", target);
            }
        }
    }
}

//地震技能
public SkillEarthQuake(target, userid)
{
    decl Float:Pos[3], Float:tPos[3];


    if(IsPlayerIncapped(target))
    {
        for(new i = 1; i <= GetMaxClients(); i++)
        {
            if (i > 32) { return; }
            if(IsPlayerTank(i))
                continue;
            if(!IsClientInGame(i) || GetClientTeam(i) != 2)
                continue;

            GetClientAbsOrigin(userid, Pos);
            GetClientAbsOrigin(i, tPos);
            if(GetVectorDistance(tPos, Pos) < GetConVarFloat(sm_lastboss_quake_radius))
            {
                EmitSoundToClient(i, SOUND_QUAKE);
                ScreenShake(i, 60.0);
                Smash(userid, i, GetConVarFloat(sm_lastboss_quake_force), 1.0, 1.5);
            }
        }
    }
}

//致盲黑屏
public SkillDreadClaw(target)
{
    visibility = GetConVarInt(sm_lastboss_dreadrate);
    CreateTimer(GetConVarFloat(sm_lastboss_dreadinterval), DreadTimer, target);
    EmitSoundToAll(SOUND_DCLAW, target);
    ScreenFade(target, 0, 0, 0, visibility, 0, 0);
}

//重力攻击
public SkillGravityClaw(target)
{
    if(IsValidPlayer(target) && IsValidEntity(target))
    {
        SetEntityGravity(target, 0.3);
        CreateTimer(GetConVarFloat(sm_lastboss_gravityinterval), GravityTimer, target);
        EmitSoundToAll(SOUND_GCLAW, target);
        ScreenFade(target, 0, 0, 100, 80, 4000, 1);
        ScreenShake(target, 30.0);
    }    
}

//红血攻击(type=1是红血攻击的DMG,type=2是火焰喷发的DMG)
public SkillBurnClaw(target, type)
{
    new health = GetClientHealth(target);
    new Float:buffer = GetEntPropFloat(target, Prop_Send, "m_healthBuffer");
    new String:strbuffer[32];
    new dmg;
    if (type == 1)
    {
        if (health <= 1 && buffer > 1.0)
        {
            FloatToString(buffer, strbuffer, sizeof(strbuffer));
            dmg = StringToInt(strbuffer) - GetConVarInt(sm_lastboss_tankry_hxdmg);
        }
        else
        {
            dmg = health - GetConVarInt(sm_lastboss_tankry_hxdmg);
        }
    }
    else if (type == 2)
    {
        if (health <= 1 && buffer > 1.0)
        {
            FloatToString(buffer, strbuffer, sizeof(strbuffer));
            dmg = StringToInt(strbuffer) - 50;
        }
        else
        {
            dmg = health - 50;
        }
    }
    else
    {
        dmg = health;
    }

    if(health > 0 && !IsPlayerIncapped(target))
    {
        if (dmg < 1)
        {
            if (health <= 1 && buffer > 1.0)
            {
                SetEntPropFloat(target, Prop_Send, "m_healthBuffer", 1.0);
            }
            else
            {
                SetEntityHealth(target, 1);
            }
        }
        else
        {
            if (health <= 1 && buffer > 1.0)
            {
                SetEntPropFloat(target, Prop_Send, "m_healthBuffer", float(dmg));
            }
            else
            {
                SetEntityHealth(target, dmg);
            }
        }
    }
    EmitSoundToAll(SOUND_BCLAW, target);
    ScreenFade(target, 200, 0, 0, 150, 80, 1);
    ScreenShake(target, 50.0);
}

//火焰石头和爆炸石头
public SkillCometStrike(target, type)
{
    decl Float:pos[3];
    GetClientAbsOrigin(target, pos);

    if(type == MOLOTOV)
    {
        LittleFlower(pos, EXPLODE);
        LittleFlower(pos, MOLOTOV);
    }
    else if(type == EXPLODE)
    {
        LittleFlower(pos, EXPLODE);
    }
}

//火焰喷发
public SkillFlameGush(target, userid)
{
    decl Float:pos[3];

    SkillBurnClaw(target, 2);
    GetClientAbsOrigin(userid, pos);
    LittleFlower(pos, MOLOTOV);
}


/******************************************************
*    计时器子程序
*******************************************************/
//重力计时器
public Action:GravityTimer(Handle:timer, any:target)
{
    if(IsValidPlayer(target) && IsValidEntity(target))
    {
        SetEntityGravity(target, 1.0);
        KillTimer(timer);
    }
}

//隐形计时器
public Action:StealthTimer(Handle:timer, any:client)
{
    if(IsPlayerTank(client) && tanktype[client] == TANKYL)
    {
        alpharate = 255;
        Remove(client);
    }
}

//致盲计时器
public Action:DreadTimer(Handle:timer, any:target)
{
    visibility -= 10;
    if(visibility < 0)  visibility = 0;
    ScreenFade(target, 0, 0, 0, visibility, 0, 1);
    if(visibility <= 0)
    {
        visibility = 0;
        ScreenFade(target, 0, 0, 0, 0, 0, 1);
        KillTimer(timer);
    }
}

//坦克选择提示计时器
public Action:Timer_Tank_Select_Msg(Handle:timer)
{
    Msg_Timer = timer;
    //PrintToChatAll("计时器运行中");
    for (new i = 1; i <= MaxClients; i++)
    {
        if (i > 32) { return Plugin_Continue; }
        if (IsClientInGame(i) && !IsFakeClient(i) && GetClientTeam(i) == 3)
        {
            if (tanktype[i] < 1)
            {
                //CPrintToChat(i, "{lightgreen}输入 !tk 选择你成为坦克时的坦克类型,不选择将系统随机选择.");
                //PrintHintText(i, "输入 !tk 选择你成为坦克时的坦克类型,不选择将系统随机选择.");
                SelectTypePanel(i);
            }
        }
    }
    return Plugin_Continue;
}

public Action:SmSetTank(client, args)
{
	//CPrintToChat(client, "{lightgreen}你已经选择了 %d", tanktype[client]);
	
	if(IsValidPlayer(client) && GetClientTeam(client) == 3 && tanktype[client] < 1)
	{
		SelectTypePanel(client);		
	}
	else
	{	
		if(IsValidPlayer(client) && GetClientTeam(client) == 3)
		{
			if (tanktype[client] == TANKRY)// 熔岩坦克 1
			{			
				CPrintToChat(client, "{lightgreen}你已经选择了熔岩坦克类型！");
			}
			else if (tanktype[client] == TANKZL)// 重力坦克 2
			{
				CPrintToChat(client, "{lightgreen}你已经选择了重力坦克类型！");
			}
			else if (tanktype[client] == TANKKJ)// 恐惧坦克 3
			{
				CPrintToChat(client, "{lightgreen}你已经选择了恐惧坦克类型！");
			}
			else if (tanktype[client] == TANKYL)// 幽灵坦克 4
			{
				CPrintToChat(client, "{lightgreen}你已经选择了幽灵坦克类型！");
			}
			else if (tanktype[client] == TANKDZ)// 地震坦克 5
			{
				CPrintToChat(client, "{lightgreen}你已经选择了地震坦克类型！");
			}
			else if (tanktype[client] == TANKYJ)// 游击坦克 6
			{
				CPrintToChat(client, "{lightgreen}你已经选择了游击坦克类型！");
			}
		}				
	}
}
/******************************************************
*    Gimmick functions
*******************************************************/
//隐形调用
public Action:Remove(ent)
{
    if(IsValidEntity(ent))
    {
        CreateTimer(0.1, fadeout, ent, TIMER_REPEAT);
        SetEntityRenderMode(ent, RENDER_TRANSCOLOR);
    }
}

//隐形计时器
public Action:fadeout(Handle:Timer, any:ent)
{
    if(!IsValidEntity(ent) || tanktype[ent] != TANKYL || !IsPlayerTank(ent))
    {
        KillTimer(Timer);
        return;
    }
    alpharate -= 2;
    if (alpharate < 0)  alpharate = 0;
    SetEntityRenderMode(ent, RENDER_TRANSCOLOR);
    SetEntityRenderColor(ent, 80, 80, 255, alpharate);
    if(alpharate <= 0)
    {
        KillTimer(Timer);
    }
}

//火焰爆炸效果
public LittleFlower(Float:pos[3], type)
{
    /* 火焰(type=0) 或 爆炸(type=1) */
    new entity = CreateEntityByName("prop_physics");
    if (IsValidEntity(entity))
    {
        pos[2] += 10.0;
        if (type == 0)
            /* fire */
            DispatchKeyValue(entity, "model", ENTITY_GASCAN);
        else
            /* explode */
            DispatchKeyValue(entity, "model", ENTITY_PROPANE);
        DispatchSpawn(entity);
        SetEntData(entity, GetEntSendPropOffs(entity, "m_CollisionGroup"), 1, 1, true);
        TeleportEntity(entity, pos, NULL_VECTOR, NULL_VECTOR);
        AcceptEntityInput(entity, "break");
    }
}

//地震技能调用
public Smash(client, target, Float:power, Float:powHor, Float:powVec)
{
    /* Blow off target */
    decl Float:HeadingVector[3], Float:AimVector[3];
    GetClientEyeAngles(client, HeadingVector);

    AimVector[0] = FloatMul(Cosine(DegToRad(HeadingVector[1])) ,power * powHor);
    AimVector[1] = FloatMul(Sine(DegToRad(HeadingVector[1])) ,power * powHor);

    decl Float:current[3];
    GetEntPropVector(target, Prop_Data, "m_vecVelocity", current);

    decl Float:resulting[3];
    resulting[0] = FloatAdd(current[0], AimVector[0]);
    resulting[1] = FloatAdd(current[1], AimVector[1]);
    resulting[2] = power * powVec;

    TeleportEntity(target, NULL_VECTOR, NULL_VECTOR, resulting);
}

//屏幕颜色
public ScreenFade(target, red, green, blue, alpha, duration, type)
{
    if(IsValidPlayer(target))
    {
        new Handle:msg = StartMessageOne("Fade", target);
        BfWriteShort(msg, 500);
        BfWriteShort(msg, duration);
        if (type == 0)
            BfWriteShort(msg, (0x0002 | 0x0008));
        else
            BfWriteShort(msg, (0x0001 | 0x0010));
        BfWriteByte(msg, red);
        BfWriteByte(msg, green);
        BfWriteByte(msg, blue);
        BfWriteByte(msg, alpha);
        EndMessage();
    }    
}

//屏幕震动
public ScreenShake(target, Float:intensity)
{
    if(IsValidPlayer(target))
    {
        new Handle:msg;
        msg = StartMessageOne("Shake", target);

        BfWriteByte(msg, 0);
        BfWriteFloat(msg, intensity);
        BfWriteFloat(msg, 10.0);
        BfWriteFloat(msg, 3.0);
        EndMessage();
    }    
}

/******************************************************
*    粒子控制子程序
*******************************************************/
/* 显示你想要的粒子效果 */
public ShowParticle(Float:pos[3], String:particlename[], Float:time)
{
    new particle = CreateEntityByName("info_particle_system");
    if (IsValidEdict(particle))
    {
        TeleportEntity(particle, pos, NULL_VECTOR, NULL_VECTOR);
        DispatchKeyValue(particle, "effect_name", particlename);
        DispatchKeyValue(particle, "targetname", "particle");
        DispatchSpawn(particle);
        ActivateEntity(particle);
        AcceptEntityInput(particle, "start");
        CreateTimer(time, DeleteParticles, particle);
    }
}

/* 连接粒子 */
public AttachParticle(ent, String:particleType[])
{
    decl String:tName[64];
    new particle = CreateEntityByName("info_particle_system");
    if (IsValidEdict(particle))
    {
        new Float:pos[3];
        GetEntPropVector(ent, Prop_Send, "m_vecOrigin", pos);
        TeleportEntity(particle, pos, NULL_VECTOR, NULL_VECTOR);
        GetEntPropString(ent, Prop_Data, "m_iName", tName, sizeof(tName));
        DispatchKeyValue(particle, "targetname", "tf2particle");
        DispatchKeyValue(particle, "parentname", tName);
        DispatchKeyValue(particle, "effect_name", particleType);
        DispatchSpawn(particle);
        SetVariantString(tName);
        AcceptEntityInput(particle, "SetParent", particle, particle, 0);
        ActivateEntity(particle);
        AcceptEntityInput(particle, "start");
    }
}

/* 删除粒子 */
public Action:DeleteParticles(Handle:timer, any:particle)
{
    if (IsValidEntity(particle))
    {
        new String:classname[64];
        GetEdictClassname(particle, classname, sizeof(classname));
        if (StrEqual(classname, "info_particle_system", false))
            RemoveEdict(particle);
    }
}

/* 预先缓存 */
public PrecacheParticle(String:particlename[])
{
    new particle = CreateEntityByName("info_particle_system");
    if (IsValidEdict(particle))
    {
        DispatchKeyValue(particle, "effect_name", particlename);
        DispatchKeyValue(particle, "targetname", "particle");
        DispatchSpawn(particle);
        ActivateEntity(particle);
        AcceptEntityInput(particle, "start");
        CreateTimer(0.01, DeleteParticles, particle);
    }
}

/******************************************************
*    其他子程序
*******************************************************/
bool:IsPlayerIncapped(client)
{
    if (GetEntProp(client, Prop_Send, "m_isIncapacitated", 1))
        return true;
    else
        return false;
}

/*
GetAnyClient()
{
    for(new i = 1; i <= MaxClients; i++)
    {
        if(IsValidEntity(i) && IsClientInGame(i))
            return i;
    }
    return -1;
}
*/
/******************************************************
*    设置坦克类型
*******************************************************/
public SetTankType(client, type)
{
    tanktype[client] = type;
    new maxhealth;
    new Float:speed;
    if(IsValidPlayer(client) && IsValidEntity(client))
    {        
        if (tanktype[client] < TANKRY || tanktype[client] > TANKYJ)
        {
            tanktype[client] = GetRandomInt(TANKRY, TANKYJ);
        }

        if (tanktype[client] == TANKRY)
        {
            maxhealth = GetConVarInt(sm_lastboss_tankry_health);
            SetEntProp(client, Prop_Data, "m_iMaxHealth", maxhealth);
            SetEntProp(client, Prop_Data, "m_iHealth", maxhealth);
            speed = GetConVarFloat(sm_lastboss_tankry_speed);
            SetEntDataFloat(client,g_iLaggedMovementO, speed ,true);
            //SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", speed);
            ClientCommand(client, "sm_buy");        //修复8分健康BUG的利用
            //颜色设置
            SetEntityRenderMode(client, RenderMode:0);
            DispatchKeyValue(client, "rendercolor", "255 80 80");
            CPrintToChatAll("{green}熔岩坦克{lightgreen}出场了!当前控制者是: {green}%N \n生命值: {lightgreen}%d  {green}移动倍数: {lightgreen}%.2f \n{olive}该坦克攻击会造成红眼效果,近战攻击时会被熔岩爆炸灼伤!", client, maxhealth, speed);
            CPrintToChatAll("{olive}丢出的石头也会产生火焰效果!");
        }
        else if (tanktype[client] == TANKZL)
        {
            maxhealth = GetConVarInt(sm_lastboss_tankzl_health);
            SetEntProp(client, Prop_Data, "m_iMaxHealth", maxhealth);
            SetEntProp(client, Prop_Data, "m_iHealth", maxhealth);
            speed = GetConVarFloat(sm_lastboss_tankzl_speed);
            SetEntDataFloat(client,g_iLaggedMovementO, speed ,true);
            ClientCommand(client, "sm_buy");        //修复8分健康BUG的利用
            //颜色设置
            SetEntityRenderMode(client, RenderMode:0);
            DispatchKeyValue(client, "rendercolor", "80 255 80");
            CPrintToChatAll("{green}重力坦克{lightgreen}出场了!当前控制者是: {green}%N \n生命值: {lightgreen}%d  {green}移动倍数: {lightgreen}%.2f \n{olive}该坦克攻击会造成低重力效果,并且对所有近战武器免疫!", client, maxhealth, speed);
        }
        else if (tanktype[client] == TANKKJ)
        {
            maxhealth = GetConVarInt(sm_lastboss_tankkj_health);
            SetEntProp(client, Prop_Data, "m_iMaxHealth", maxhealth);
            SetEntProp(client, Prop_Data, "m_iHealth", maxhealth);
            speed = GetConVarFloat(sm_lastboss_tankkj_speed);
            SetEntDataFloat(client,g_iLaggedMovementO, speed ,true);
            ClientCommand(client, "sm_buy");        //修复8分健康BUG的利用
            //颜色设置
            SetEntityRenderMode(client, RenderMode:0);
            DispatchKeyValue(client, "rendercolor", "90 90 90");
            CPrintToChatAll("{green}恐惧坦克{lightgreen}出场了!当前控制者是: {green}%N \n生命值: {lightgreen}%d  {green}移动倍数: {lightgreen}%.2f \n{olive}该坦克攻击会造成短时间致盲状态,请小心对待!", client, maxhealth, speed);
        }
        else if (tanktype[client] == TANKYL)
        {
            maxhealth = GetConVarInt(sm_lastboss_tankyl_health);
            SetEntProp(client, Prop_Data, "m_iMaxHealth", maxhealth);
            SetEntProp(client, Prop_Data, "m_iHealth", maxhealth);
            speed = GetConVarFloat(sm_lastboss_tankyl_speed);
            SetEntDataFloat(client,g_iLaggedMovementO, speed ,true);
            ClientCommand(client, "sm_buy");        //修复8分健康BUG的利用
            //颜色设置
            SetEntityRenderMode(client, RenderMode:0);
            DispatchKeyValue(client, "rendercolor", "80 80 255");
            //创建隐形计时器
            CreateTimer(GetConVarFloat(sm_lastboss_stealth_third), StealthTimer, client);
            CPrintToChatAll("{green}幽灵坦克{lightgreen}出场了!当前控制者是: {green}%N \n生命值: {lightgreen}%d  {green}移动倍数: {lightgreen}%.2f \n{olive}该坦克会快速逐渐隐形,在无形中扼杀幸存者!", client, maxhealth, speed);
        }
        else if (tanktype[client] == TANKDZ)
        {
            maxhealth = GetConVarInt(sm_lastboss_tankdz_health);
            SetEntProp(client, Prop_Data, "m_iMaxHealth", maxhealth);
            SetEntProp(client, Prop_Data, "m_iHealth", maxhealth);
            speed = GetConVarFloat(sm_lastboss_tankdz_speed);
            SetEntDataFloat(client,g_iLaggedMovementO, speed ,true);
            ClientCommand(client, "sm_buy");        //修复8分健康BUG的利用
            //颜色设置
            SetEntityRenderMode(client, RenderMode:0);
            DispatchKeyValue(client, "rendercolor", "255 255 80");
            CPrintToChatAll("{green}地震坦克{lightgreen}出场了!当前控制者是: {green}%N \n生命值: {lightgreen}%d  {green}移动倍数: {lightgreen}%.2f \n{olive}该坦克攻击倒地幸存者,会使他周围的战友震飞起来!", client, maxhealth, speed);
            CPrintToChatAll("{olive}丢出的石头也会产生爆炸效果!");
        }
        else if (tanktype[client] == TANKYJ)
        {			
            maxhealth = GetConVarInt(sm_lastboss_tankyj_health);
            SetEntProp(client, Prop_Data, "m_iMaxHealth", maxhealth);
            SetEntProp(client, Prop_Data, "m_iHealth", maxhealth);
            speed = GetConVarFloat(sm_lastboss_tankyj_speed);
            SetEntDataFloat(client,g_iLaggedMovementO, speed ,true);
            ClientCommand(client, "sm_buy");        //修复8分健康BUG的利用
            //重力设置
            SetEntityGravity(client, 0.2);
            //颜色设置
            SetEntityRenderMode(client, RenderMode:0);
            DispatchKeyValue(client, "rendercolor", "255 20 255");
            CPrintToChatAll("{green}游击坦克{lightgreen}出场了!当前控制者是: {green}%N \n生命值: {lightgreen}%d  {green}移动倍数: {lightgreen}%.2f \n{olive}该坦克拥有极限的速度和跳跃能力,是TANK中的运动健将.", client, maxhealth, speed);
        }
        //速度设置检测
        CreateTimer(1.0, tankspeedcheck, client);
    }
}
/* 获取随机有效幸存者，给予tank */
public GetRandomPlayer(Team)
{
    new Handle:array;
    array = CreateArray(1, 0);
    
    for(new i = 1; i <= MaxClients; i++)
    {
        if(!IsValidPlayer(i, false) || GetClientTeam(i) != Team)
            continue;
            
        PushArrayCell(array, i);
    }
    
    
    if (GetArraySize(array) <= 0)
        return 0;
    
    new maxsize = GetArraySize(array) - 1;
    new clientNum = GetArrayCell(array, GetRandomInt(0, maxsize));
//PrintToChatAll("当前轮换tank获得者【 %N 】", clientNum);
//PrintToChatAll("当前最大玩家数 %d ", maxsize);
    new tank_count_temp = 0;
    while(IsPlayerTank(clientNum) || GetClientTeam(clientNum) != 3 || IsFakeClient(clientNum) || !IsClientInGame(clientNum))
    {
     //   PrintToChatAll("当tank_count %d ", tank_count_temp);
        if(tank_count_temp >= maxsize)
        {
            for(new i = 1; i <= MaxClients; i++)
            {
                if(!IsPlayerTank(i) && IsValidPlayer(i, false) && IsValidEntity(i) && GetClientTeam(i) == 3)
                {
                    //PrintToChatAll("顺序给予");
                    return i;
                }
            }
            //PrintToChatAll("没有可用玩家");
            return -1;
        }
        tank_count_temp++;
        clientNum = GetArrayCell(array, GetRandomInt(0, maxsize));
        //PrintToChatAll("重复tank获得者__【 %N 】", clientNum);
    }
    return clientNum;
}

//坦克属性修正,第一次重生属性设置无效后在重新设置
public Action:tankspeedcheck(Handle:timer, any:client)
{
    if (client < 1 || !IsPlayerTank(client) || !IsClientInGame(client)) { return Plugin_Stop; }
    new Float:getspeed = GetEntDataFloat(client, g_iLaggedMovementO);
    new gethealth = GetEntProp(client, Prop_Data, "m_iMaxHealth");
    new maxhealth;
    if (tanktype[client] == TANKRY)
    {
        if (getspeed != GetConVarFloat(sm_lastboss_tankry_speed) || gethealth != GetConVarInt(sm_lastboss_tankry_health))
        {
            maxhealth = GetConVarInt(sm_lastboss_tankry_health);
            SetEntProp(client, Prop_Data, "m_iMaxHealth", maxhealth);
            SetEntProp(client, Prop_Data, "m_iHealth", maxhealth);
            SetEntDataFloat(client,g_iLaggedMovementO, GetConVarFloat(sm_lastboss_tankry_speed) ,true);
            //SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", GetConVarFloat(sm_lastboss_tankry_speed));
            return Plugin_Stop;
        }
    }
    else if (tanktype[client] == TANKZL)
    {
        if (getspeed != GetConVarFloat(sm_lastboss_tankzl_speed) || gethealth != GetConVarInt(sm_lastboss_tankzl_health))
        {
            maxhealth = GetConVarInt(sm_lastboss_tankzl_health);
            SetEntProp(client, Prop_Data, "m_iMaxHealth", maxhealth);
            SetEntProp(client, Prop_Data, "m_iHealth", maxhealth);
            SetEntDataFloat(client,g_iLaggedMovementO, GetConVarFloat(sm_lastboss_tankzl_speed) ,true);
            //SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", GetConVarFloat(sm_lastboss_tankzl_speed));
            return Plugin_Stop;
        }
    }
    else if (tanktype[client] == TANKKJ)
    {
        if (getspeed != GetConVarFloat(sm_lastboss_tankkj_speed) || gethealth != GetConVarInt(sm_lastboss_tankkj_health))
        {
            maxhealth = GetConVarInt(sm_lastboss_tankkj_health);
            SetEntProp(client, Prop_Data, "m_iMaxHealth", maxhealth);
            SetEntProp(client, Prop_Data, "m_iHealth", maxhealth);
            SetEntDataFloat(client,g_iLaggedMovementO, GetConVarFloat(sm_lastboss_tankkj_speed) ,true);
            //SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", GetConVarFloat(sm_lastboss_tankkj_speed));
            return Plugin_Stop;
        }
    }
    else if (tanktype[client] == TANKYL)
    {
        if (getspeed != GetConVarFloat(sm_lastboss_tankyl_speed) || gethealth != GetConVarInt(sm_lastboss_tankyl_health))
        {
            maxhealth = GetConVarInt(sm_lastboss_tankyl_health);
            SetEntProp(client, Prop_Data, "m_iMaxHealth", maxhealth);
            SetEntProp(client, Prop_Data, "m_iHealth", maxhealth);
            SetEntDataFloat(client,g_iLaggedMovementO, GetConVarFloat(sm_lastboss_tankyl_speed) ,true);
            //SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", GetConVarFloat(sm_lastboss_tankyl_speed));
            return Plugin_Stop;
        }
    }
    else if (tanktype[client] == TANKDZ)
    {
        if (getspeed != GetConVarFloat(sm_lastboss_tankdz_speed) || gethealth != GetConVarInt(sm_lastboss_tankdz_health))
        {
            maxhealth = GetConVarInt(sm_lastboss_tankdz_health);
            SetEntProp(client, Prop_Data, "m_iMaxHealth", maxhealth);
            SetEntProp(client, Prop_Data, "m_iHealth", maxhealth);
            SetEntDataFloat(client,g_iLaggedMovementO, GetConVarFloat(sm_lastboss_tankdz_speed) ,true);
            //SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", GetConVarFloat(sm_lastboss_tankdz_speed));
            return Plugin_Stop;
        }
    }
    else if (tanktype[client] == TANKYJ)
    {
		
        if (getspeed != GetConVarFloat(sm_lastboss_tankyj_speed) || gethealth != GetConVarInt(sm_lastboss_tankyj_health))
        {			
            maxhealth = GetConVarInt(sm_lastboss_tankyj_health);
            SetEntProp(client, Prop_Data, "m_iMaxHealth", maxhealth);
            SetEntProp(client, Prop_Data, "m_iHealth", maxhealth);
            SetEntDataFloat(client,g_iLaggedMovementO, GetConVarFloat(sm_lastboss_tankyj_speed) ,true);
            //SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", GetConVarFloat(sm_lastboss_tankyj_speed));
            //重力设置
            SetEntityGravity(client, 0.2);
            return Plugin_Stop;
        }
    }

    if (changehealth >= 1)
    {
        SetEntProp(client, Prop_Data, "m_iHealth", changehealth);
        changehealth = 0;
    }
    return Plugin_Continue;
}

/*  坦克转换控制 */
public TankChange(client)
{
    if(client <= 0 || client > MaxClients)
        return;
    if(!IsClientInGame(client))
        return;

    if (!IsFakeClient(client))
    {
        changehealth = GetEntProp(client, Prop_Data, "m_iHealth");
    }
    //恢复数据
    SetEntityGravity(client, 1.0);
    if (tanktype[client] == TANKYL)
    {
        SetEntityRenderMode(client, RENDER_TRANSCOLOR);
        SetEntityRenderColor(client, 255, 255, 255, 255);
    }

    //杀死坦克
    //ForcePlayerSuicide(client);

    //重生坦克
    //new flager = GetAnyClient();
    //new flag = GetCommandFlags("z_spawn tank auto");
    //SetCommandFlags("z_spawn tank auto", flag & ~FCVAR_CHEAT);
    //FakeClientCommand(flager, "z_spawn tank auto");
}


public SelectTypePanel(client)
{
    new Handle:Panel = CreatePanel();
    SetPanelTitle(Panel, "选择成为坦克时你的坦克类型:");
    DrawPanelItem(Panel, "熔岩坦克");
    DrawPanelItem(Panel, "重力坦克");
    DrawPanelItem(Panel, "恐惧坦克");
    DrawPanelItem(Panel, "幽灵坦克");
    DrawPanelItem(Panel, "地震坦克");
    DrawPanelItem(Panel, "游击坦克");

    SendPanelToClient(Panel, client, TypePanelCallBack, 30);
    CloseHandle(Panel);
}

public TypePanelCallBack(Handle:menu, MenuAction:action, client, param)
{
    if (!IsClientInGame(client) || IsFakeClient(client)) { return; }
    if (action == MenuAction_Select)
    {
        if (param == TANKRY)
        {
            CPrintToChat(client, "{olive}已经保存你选择的{lightgreen}熔岩坦克");
            tanktype[client] = param;
            ClientCommand(client, "sm_s");
        }
        else if (param == TANKZL)
        {
            CPrintToChat(client, "{olive}已经保存你选择的{lightgreen}重力坦克");
            tanktype[client] = param;
            ClientCommand(client, "sm_s");
        }
        else if (param == TANKKJ)
        {
            CPrintToChat(client, "{olive}已经保存你选择的{lightgreen}恐惧坦克");
            tanktype[client] = param;
            ClientCommand(client, "sm_s");
        }
        else if (param == TANKYL)
        {
            CPrintToChat(client, "{olive}已经保存你选择的{lightgreen}幽灵坦克");
            tanktype[client] = param;
            ClientCommand(client, "sm_s");
        }
        else if (param == TANKDZ)
        {
            CPrintToChat(client, "{olive}已经保存你选择的{lightgreen}地震坦克");
            tanktype[client] = param;
            ClientCommand(client, "sm_s");
        }
        else if (param == TANKYJ)
        {
            CPrintToChat(client, "{olive}已经保存你选择的{lightgreen}游击坦克");
            tanktype[client] = param;
            ClientCommand(client, "sm_s");
        }
    }
}
//
public bool:IsPlayerTank (client)
{
    if(IsValidPlayer(client))
    {
    
        new String:class[150];
        GetClientModel(client, class, sizeof(class));
        return (StrContains(class, "hulk", false) != -1);
    }
    else
    {
        return false;
    }
//    return ((GetClientTeam(client) == 3) && (GetEntProp(client, Prop_Send, "m_zombieClass") == ZC_TANK));
}
/* 判断玩家是否有效 */
stock bool:IsValidPlayer(Client, bool:AllowBot = true, bool:AllowDeath = true)
{
    if (Client < 1 || Client > MaxClients)
        return false;
    if (!IsClientConnected(Client) || !IsClientInGame(Client))
        return false;
    if (!AllowBot)
    {
        if (IsFakeClient(Client))
            return false;
    }

    if (!AllowDeath)
    {
        if (!IsPlayerAlive(Client))
            return false;
    }    
    
    return true;
}
/******************************************************
*    结束
*******************************************************/
